package com.hzqiuxm.tdddemo001.junit5demo.parameterized.aggregation;

import com.hzqiuxm.tdddemo001.junit5demo.Gender;
import com.hzqiuxm.tdddemo001.junit5demo.Person;
import org.junit.jupiter.api.extension.ParameterContext;
import org.junit.jupiter.params.aggregator.ArgumentsAccessor;
import org.junit.jupiter.params.aggregator.ArgumentsAggregationException;
import org.junit.jupiter.params.aggregator.ArgumentsAggregator;

import java.time.LocalDate;

/**
 * Copyright © 2021年 tdd-demo-001. All rights reserved.
 *
 * @author 临江仙 hzqiuxm@163.com
 * 自定义的参数聚合类
 * @date 2021/2/7 11:30
 */
public class PersonAggregator implements ArgumentsAggregator {
    @Override
    public Object aggregateArguments(ArgumentsAccessor arguments, ParameterContext context)
            throws ArgumentsAggregationException {

        return new Person(arguments.getString(0),
                arguments.getString(1),
                arguments.get(2, Gender.class),
                arguments.get(3, LocalDate.class));
    }
}
